package com.innerex.inexclear.core.dao.hibernate;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.innerex.inexclear.core.dao.ClearingRuleDao;
import com.innerex.inexclear.core.model.ClearingRule;

/**
 * This class interacts with Spring's HibernateTemplate to save/delete and
 * retrieve clearingRule objects.
 * 
 *@author <a href="mailto:evencia@innerex.com"> Edoardo Vencia
 *         (evencia@innerex.com)</a>
 */
@Repository
public class ClearingRuleDaoHibernate extends
		GenericDaoHibernate<ClearingRule, Long> implements ClearingRuleDao {

	/**
	 * Constructor to create a Generics-based version using ClearingRule as the
	 * entity
	 */
	public ClearingRuleDaoHibernate() {
		super(ClearingRule.class);
	}

	public ClearingRule getClearingRuleByJavaClass(String javaclass) {
		List clearingRules = getHibernateTemplate().find(
				"from ClearingRule where javaclass=?", javaclass);
		if (clearingRules.isEmpty()) {
			return null;
		} else {
			return (ClearingRule) clearingRules.get(0);
		}
	}
}
